//
//  PublishViewController.m
//  WuShiCity
//
//  Created by chengjie on 16/7/4.
//  Copyright © 2016年 chengjie. All rights reserved.
//

#import "PublishViewController.h"
#import "PublishListViewController.h"
#import "SelfPublishListViewController.h"
#import "PublishCollectionViewCell.h"

@interface PublishViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation PublishViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.view addSubview:self.collectionView];
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]initWithTitle:@"我的发布" style:UIBarButtonItemStylePlain target:self action:@selector(selfPublish:)];
    self.navigationItem.rightBarButtonItem = rightBtn;
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - --------我的发布的回调----
- (void)selfPublish:(UIBarButtonItem *)sender {
    
    SelfPublishListViewController *selfPublishListVC = [[SelfPublishListViewController alloc] init];
    [self.navigationController pushViewController:selfPublishListVC animated:NO];
}


#pragma mark - ------collectionView的代理方法--------
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 12;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    PublishCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PublishCell" forIndexPath:indexPath];
    
    cell.itemLabel.text = @"123456789";
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    PublishListViewController *publishListVC = [[PublishListViewController alloc] init];
    [self.navigationController pushViewController:publishListVC animated:YES];
}



#pragma mark - -------laying------
- (UICollectionView *)collectionView {
    
    if (!_collectionView) {
        
        //确定集合的布局
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.itemSize = CGSizeMake((kScreenWidth-20)/4, (kScreenWidth-20)/4);
        flowLayout.minimumInteritemSpacing = 10;
        flowLayout.minimumLineSpacing = 10;
        flowLayout.sectionInset = UIEdgeInsetsMake(9, 9, 9, 9);
        _collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
        [_collectionView registerNib:[UINib nibWithNibName:@"PublishCollectionViewCell" bundle:nil]forCellWithReuseIdentifier:@"PublishCell"];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
        
    }
    return _collectionView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
